var api = require("../../../utils/api.js"), 
util = require("../../../utils/util.js"),
app = getApp();
Page({
    data: {
        active:0,
        childrenActive:-1,
        serBannerList: [],
        proBannerList: [],
        serTabList: [],
        proTabList: [],
        serTab: "",
        serTabNum: 0,
        proTab: "",
        proTabNum: 0,
        serList: [],
        proList: [],
        childTabList: [],
        pageIndex: 1,
        pageSize: 10,
        serEmpty: !1,
        proEmpty: !1,
        serScroll: !0,
        proScroll: !0,
        isFirst: !0,
        baseImgUrl:app.globalData.baseImgUrl,
        show:false,
        isShowScroll:false,
        bangsHeight:wx.getStorageSync('navBarObj').bangsHeight
    },
    onLoad: function(t) {
      this.getServerList();
    },
    onShow:function(){
      if(this.data.proList.length>0){
        api.default.getServerList({pageIndex:1,pageSize:1}).then(res=>{
          if(res.code == 1){
            let list=Array.isArray(res.data.list)?res.data.list:[];
            if(list.length>0){
              let newA=list[0].id,oldA=this.data.proList[0].id;
              this.setData({
                isShowScroll:newA!=oldA?true:false
              })
            }
          }
        })
      }
    },
    async getServerList() {
        let param={
            pageIndex:this.data.pageIndex,
            pageSize:this.data.pageSize
        }
        let {data:{list,total}}=await api.default.getServerList(param);
        let listArr=Array.isArray(list)?list:[];
        listArr.forEach(item=>{
          item.create_time = util.formatTime2(new Date(item.create_time*1000))
        })
        this.setData({
            proScroll:listArr.length<=this.data.pageSize?true:false,
            proList: this.data.pageIndex == 1?listArr:[...this.data.proList,...listArr],
            showEmpty:total==0?true:false
        })
        
    },
    toDetailPage: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "./actionDetail?id=" + a
        })
    },
    onClose(){
        this.setData({show:false})
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        wx.showNavigationBarLoading()
        this.setData({
            pageIndex: 1,
            isShowScroll:false
        });
        this.getServerList();
        setTimeout(()=>{
          wx.hideNavigationBarLoading();
          wx.stopPullDownRefresh();
        }, 200)
    },
    onReachBottom: function() {
      if(!this.data.proScroll){
        let page=this.data.pageIndex;
        page=page+1;
        this.setData({pageIndex:page});
        this.getGoodslist()
      }
    },
    onShareAppMessage: function(e) {
      return util.shareEvent(e)
    }
});